package com.quanyan.place.thread;

import com.alibaba.fastjson.JSON;
import com.quanyan.place.biz.ISearchService;
import com.quanyan.place.entity.TbBizPlace;
import com.quanyan.place.mapper.TbBizPlaceMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * Created by jingliu on 16/7/14.
 */
public class SolrIndexThread implements Runnable{

    private Logger logger = LoggerFactory.getLogger(SolrIndexThread.class);

    private Integer placeid;

    private List<String> ids;
    private TbBizPlaceMapper tbBizPlaceMapper;
    private ISearchService searchService;


    public SolrIndexThread(Integer placeid, List<String> ids, TbBizPlaceMapper tbBizPlaceMapper, ISearchService searchService) {
        this.placeid = placeid;
        this.ids = ids;
        this.tbBizPlaceMapper = tbBizPlaceMapper;
        this.searchService = searchService;
    }


    @Override
    public void run() {
        // 增加索引
        logger.debug("————————————————————————开始加索引——————————————————————");
        try {
            TbBizPlace tbBizPlace = this.tbBizPlaceMapper.selectByPrimaryKey(placeid);
            System.out.println(JSON.toJSON(ids));
            this.searchService.addPlaceIndex(tbBizPlace, ids);
        } catch (Exception e) {
            logger.error(e.getMessage());
            logger.error("增加索引失败!");
        }
    }
}
